﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using TestMySqlConnetPoll;
using System.Threading;

namespace View.Setting.TCRepair
{
    public partial class TCRepairForm : DevExpress.XtraEditors.XtraForm
    {
        //天窗操作对象
        private TianChuangXiuTable tianchuang = new TianChuangXiuTable();
        private DataTable dt = new DataTable();

        public TCRepairForm()
        {
            InitializeComponent();

            RichTextBox rtb = new RichTextBox();
            rtb.Dock = DockStyle.Fill;
            PopupContainerControl popupControl = new PopupContainerControl();
            popupControl.Controls.Add(rtb);

            repositoryItemPopupContainerEdit1.PopupControl = popupControl;

            dt.Columns.Add("time_start");
            dt.Columns.Add("time_end");
            dt.Columns.Add("detail");
            dt.Columns.Add("opera_person");
            dt.Columns.Add("type");

            dt.Rows.Add(new object[] { "123", "123", "阿凡达发发发发发生大发发阿凡达发发发发发生大发发阿凡达发发发发发生大发发阿凡达发发发发发生大发发阿凡达发发发发发生大发发", "123" });
            dt.Rows.Add(new object[] { "123", "123", "阿凡达发发发发发生大发发阿凡达发发发发发生大发发阿凡达发发发发发生大发发阿凡达发发发发发生大发发阿凡达发发发发发生大发发", "123" });
            dt.Rows.Add(new object[] { "123", "123", "阿凡达发发发发发生大发发阿凡达发发发发发生大发发阿凡达发发发发发生大发发阿凡达发发发发发生大发发阿凡达发发发发发生大发发", "123" });

            this.gridControl1.DataSource = dt;
        }

        //判断是否需要弹出右键菜单
        bool noOpen = false;
        private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
        {
            if (e.HitInfo.HitTest == DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitTest.EmptyRow)
            {
                noOpen = true;
            }
            else
            {
                noOpen = false;
            }
    
        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            if (noOpen)
                e.Cancel = true;
        }

        /// <summary>
        /// 查询天窗内容数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSearch_Click(object sender, EventArgs e)
        {
            objDate start = new objDate();
            tianchuang.ReadValueList(start, start);

            while (!tianchuang.ReadyValueList)
            {
                if (tianchuang.ErrorFlag != 0)
                    return;

                Thread.Sleep(20);
            }

            dt.Rows.Clear();

            foreach (objTianChuang objTianC in tianchuang.ValueList)
            {
                dt.Rows.Add(new object[] { MySql.Time_tToDateTime(objTianC.s_time), 
                                           MySql.Time_tToDateTime(objTianC.e_time), 
                                           objTianC.WorkText, objTianC.UserName, objTianC.type });
            }
        }

        /// <summary>
        /// 添加天窗内容
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            TCRepairNewForm frm = new TCRepairNewForm();
            frm.ShowDialog();
        }

        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnPrint_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}